package JAVASE519.gedou;

import java.util.Random;

public class gedoubean {
    private String name;
    private int blood;
    //空参
    public gedoubean(){
    }
    //带参
    public gedoubean(String name,int blood){
        this.name=name;
        this.blood=blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }
    public void attack(gedoubean aizou){
        //随机攻击血量
        Random r=new Random();
        int bl= r.nextInt(20)+1;
        //还剩血量
        int retain=aizou.getBlood()-bl;
        retain=retain<0?0:retain;
        //修改被揍人的血量
        aizou.setBlood(retain);
        //this表示方法调用者
        System.out.println(this.getName()+"打了"+aizou.getName()+bl+"滴血，"+aizou.getName()+"还剩"+retain+"滴血");
    }
}
